<?php
class Admin_Model_Menu extends Zend_Db_Table{
	protected $_name = 'menu';
	protected $_primary = 'menu_id';
	/* Link tham khao : http://framework.zend.com/manual/en/zend.db.table.html */
	
	public function selectMenuItemByParentId($parent_id,$language)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/menu/route/selectMenuItemByParentId/parent_id/".$parent_id."/language_id/".$language);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
		
		return $data;
	}
	
	public function updateMenuItem($id,$data)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		if(isset($data['link']))
			$data['link'] = str_replace("/", "~", $data['link']);
		$temp = serialize($data);
		
		$return = $client->restPut("/menu/route/updateMenuItem/id/".urlencode($id)."/data/".urlencode($temp));
		return $return->getBody();		
	}
	
	public function deleteNotInMenuItem($listId,$language)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restDelete("/menu/route/deleteNotInMenuItem/listId/".urlencode(serialize($listId))."/language_id/".$language);
		return $return->getBody();		
	}
	
	public function deleteAllMenuItem($language)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restDelete("/menu/route/deleteAllMenuItem/language_id/".$language);
		return $return->getBody();			
	}	
	
	public function insertMenuItem($data)
	{// co dung
		$data['route'] = "insertMenuItem";
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPost("/menu", $data);
		return $return->getBody();		
	}
}